package com.uenpay.oem.widget;

import android.content.Context;
import android.support.v4.view.ActionProvider;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.uenpay.oem.R;

/**
 * Author: liulou
 * Date: 2017/6/12.
 * desc:
 */

public class PayCodeProvider extends ActionProvider {

    private ImageView ivIcon;
    private TextView tvTitle;

    private OnClickListener onClickListener;

    public PayCodeProvider(Context context) {
        super(context);
    }

    @Override
    public View onCreateActionView() {
        int size = getContext().getResources().getDimensionPixelSize(
                android.support.design.R.dimen.abc_action_bar_default_height_material);

        ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, size);
        View view = LayoutInflater.from(getContext())
                .inflate(R.layout.menu_paycode, null, false);

        view.setLayoutParams(layoutParams);
        ivIcon = (ImageView) view.findViewById(R.id.iv_menu_paycode_icon);
        tvTitle = (TextView) view.findViewById(R.id.tv_menu_paycode);
        tvTitle.getPaint().setFakeBoldText(true);
        view.setOnClickListener(onViewClickListener);
        return view;
    }

    private View.OnClickListener onViewClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (onClickListener != null)
                onClickListener.onClick(v);
        }
    };

    public void setOnClickListener(OnClickListener onClickListener) {
        this.onClickListener = onClickListener;
    }

    public interface OnClickListener {
        void onClick(View view);
    }

    public ImageView getIconView() {
        return ivIcon;
    }

    public TextView getTitleView() {
        return tvTitle;
    }
}

